
from datetime import datetime
from typing import List

# The Python Standard Modules(Library) and Third Modules(Library)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey, UniqueConstraint
from sqlalchemy import Integer, String, Date,Float,Boolean,DateTime
from sqlalchemy.orm import Mapped,mapped_column,relationship,backref


from . import MappedBase

# from databases.sqlite import MappedBase

# ================================== 一对多 ================================== #
class Img(MappedBase):
    __tablename__ = 'img'

    def __repr__(self) -> str:
        return f'<Modele Img {self.name}>'
    id:Mapped[int]=mapped_column(primary_key=True, index=True, autoincrement=True, comment='自动生成的机台id')

    dev_id:Mapped[int]=mapped_column(ForeignKey("dev.id"),nullable=False,comment='机台编号')
    station_id:Mapped[int]=mapped_column(ForeignKey("station.id"),nullable=False,comment='站点编号')

    created_at:Mapped[datetime]=mapped_column(DateTime(timezone=True),nullable=False, comment='拍照时间')
    meter_type:Mapped[str] = mapped_column(String(10),nullable=True,comment='仪表盘的类型,数字表头(digit)或者仪表盘(dashboard)')


    content_type:Mapped[str] = mapped_column(String(10),nullable=True,comment='识别的内容的类型:温度(temperature),湿度(humidity),温度和湿度(temp_and_humi),也就是自定义的编号')

    content_temperature: Mapped[str] = mapped_column(Float,nullable=True,comment='识别出来的内容,温度数值')
    temperature_set: Mapped[str] = mapped_column(Float,nullable=True,comment='温度的设定值')

    content_humidity: Mapped[str] = mapped_column(Float,nullable=True,comment='识别出来的内容,湿度数值')
    humidity_set: Mapped[str] = mapped_column(Float,nullable=True,comment='湿度的设定值')

    content_status: Mapped[str] = mapped_column(String(20),nullable=True,comment='机台运行状态')
    

    # 一开始,存入文件的路径,但是考虑到组合情况,所以干脆使用文件名,干脆叫做name,也就是时间戳的字符串形式就ok了
    name:Mapped[str] = mapped_column(String(100),nullable=False,comment='图片的路径,但是考虑到绝对路径和相对路径,所以只存文件的名称')


    # dev: Mapped["Dev"] = relationship(back_populates='imgs')
    # station: Mapped["Station"] = relationship(back_populates='station_imgs')


